package com.sinosoft.perfect.system._theme.dataFormat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sinosoft.perfect.common.xmlService.XmlInfoBean;
import com.sinosoft.perfect.common.xmlService.XmlProducerDom4j;
import com.sinosoft.perfect.system._.po.TTheme;

public class ThemeGridDataFormat_DHX implements IThemeGridDataFormat {

	public String dataFormatThemeGrid(List<TTheme> themeList, String themeId) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);

		if (themeList != null && themeList.size() > 0) {
			for (int i = 0; i < themeList.size(); i++) {
				TTheme theme = themeList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(theme.getThemeId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", theme.getThemeId());
				if (themeId != null && theme.getThemeId().equals(themeId)) {
					properties.put("select", "true");
				}
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(theme.getThemeId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(theme.getThemeId());
				cell2.setContent(theme.getThemeDesc());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(theme.getThemeId());
				cell3.setContent(theme.getThemeAddr());
				infos.add(cell3);
				
				XmlInfoBean cell4 = new XmlInfoBean();
				cell4.setName("cell");
				cell4.setParentId(theme.getThemeId());
				cell4.setContent(theme.getThemeDefault());
				infos.add(cell4);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}
}
